/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package infbmobile.comunicaciones;

import infbmobile.main.InfBMobile;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;

/**
 *
 * @author inftel
 */
public class Conexionfoto implements Runnable {

    private byte[] photo;
    private String txt;
    private InfBMobile midlet;

    public Conexionfoto(byte[] photo, String txt,InfBMobile midlet) {

        this.photo = photo;
        this.txt = txt;
        this.midlet=midlet;
    }

    public void run() {

        HttpConnection conexion = null;

        OutputStream salida = null;




        try {

            String miUrl = "http://"+midlet.servidorWeb+":"+midlet.puerto+"/GestionHospitalaria/RecepcionDolencias";
            conexion = (HttpConnection) Connector.open(miUrl);
            conexion.setRequestProperty("Content-Language", "es-ES");
            conexion.setRequestProperty("Content-Type", "image/jpg");
            conexion.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
            conexion.setRequestProperty("Connection", "close");
            conexion.setRequestMethod(HttpConnection.POST);


            salida = conexion.openOutputStream();
            DataOutputStream out = new DataOutputStream(salida);
            out.writeInt(photo.length);
            out.write(photo, 0, photo.length);
            out.writeUTF(txt);
            out.flush();
            out.close();
            salida.close();
            conexion.close();

        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
        }
    }
}
